<?php
require_once('kernel.inc');

$root_permission = false;
if($AUTH->permission == 'system')
{
   $modules = $MECCANO->kernel;
   $root_permission = true;
} elseif (is_array($AUTH->permission))
{
   foreach ($AUTH->permission AS $key=>$value)
   {
      $modules[$key] = $MECCANO->kernel[$key];
   }
}


$SMARTY->assign('root_permission', $root_permission);
$SMARTY->assign_by_ref('modules', $modules);


if($AUTH->logedstatus === true)
{
	if($action && $AUTH->permission == 'system')
	{
		$SMARTY->assign('modversion', $MECCANO->version);

		switch ($action)
		{

			/**
			* PROCEED SYSTEM VARS WORKING
			*/
			case 1:

			if(@count($_REQUEST['fvars']) > 0)
			{
				$SMARTY->assign('make', $MECCANO->UpdateSysVars($_REQUEST['fvars']));
			} else
			{
				$SMARTY->assign('sysvars', $MECCANO->GetSysVars());
			}

			$SMARTY->display('admin.configure.tpl.html');

			break;

			/**
			* PROCEED TREE MANAGMENT
			*/
			case 2:

			include_once(LIBRARIES.'/Sajax.php');
			sajax_init();
			$sajax_request_type = "POST";
			$sajax_remote_uri = "/admin/treemanager.php";
			sajax_export("GetInTree");
			sajax_export("GetNode");
			sajax_export("ProcessingData");
			sajax_handle_client_request();
			$SMARTY->assign('WRAPPER', sajax_get_javascript());
			$SMARTY->display('admin.tree.tpl.html');

			break;

			/**
			 * Company Information managment
			 */
			case 4:

			if($submit != false)
			{
			   $ll = $MECCANO->system['lang'];
			   for($i=0,$t=count($ll); $i<$t; $i++)
			   {
			      $company['name'][$ll[$i]]    = isset($_REQUEST['comp_name'][$ll[$i]])    ? prepare_str($_REQUEST['comp_name'][$ll[$i]])    : false;
				   $company['address'][$ll[$i]] = isset($_REQUEST['comp_address'][$ll[$i]]) ? prepare_str($_REQUEST['comp_address'][$ll[$i]]) : false;
			      $company['webname'][$ll[$i]] = isset($_REQUEST['comp_webname'][$ll[$i]]) ? prepare_str($_REQUEST['comp_webname'][$ll[$i]]) : false;
			   }
			   unset($ll);

				$company['email'] = isset($_REQUEST['comp_email']) ? isEmail($_REQUEST['comp_email'])     : false;
				$company['icq']   = isset($_REQUEST['comp_icq'])   ? isDigit($_REQUEST['comp_icq'])       : false;
				$company['phone'] = isset($_REQUEST['comp_phone']) ? prepare_str($_REQUEST['comp_phone']) : false;
				$company['fax']   = isset($_REQUEST['comp_fax'])   ? prepare_str($_REQUEST['comp_fax'])   : false;
				$company['regnm'] = isset($_REQUEST['comp_regnm']) ? isAlpha($_REQUEST['comp_regnm'])     : false;

				$MECCANO->SetCompanyInfo($company);
			}

			$SMARTY->assign('company', $MECCANO->GetCompanyInfo());
			$SMARTY->display('admin.companyinfo.tpl.html');

			break;
		}

	} else
	{
		$SMARTY->display('admin.meccano.tpl.html');
	}
} else
{
	echo $AUTH->frame_redirector();
}


/**
* ACTIONS:
* 1 - View System Configs
* 2 - Tree editor
* 3 - Edit ROOT User info
* 4 - Company Information
*/

?>